var express = require('express');
var router = express.Router();
const dataCtrl = require('../controllers/user.controller')

// rest api get/post/put/delete
function verifyToken(req, res, next) {
    //没有取得req.headers
    const bearerHeader = req.headers['authorization'];
    // console.log(req.headers)
    // console.log(req.headers['authorization'])
    if (typeof bearerHeader !== "undefined") {
        const bearer = bearerHeader.split(' ');
        const bearerToken = bearer[1];
        req.token = bearerToken;
        next()
    } else {
        res.sendStatus(403)
    }
}
//用户路由
router.post('/data', dataCtrl.create);
router.get('/data/:id', dataCtrl.getData);
router.put('/data/:id', dataCtrl.update);
router.delete('/data/:id', dataCtrl.remove);
router.post('/list', verifyToken, dataCtrl.list);
router.post('/data/removes', dataCtrl.removes);
router.post('/login', dataCtrl.login);


// router.post('/', dataCtrl.loginForm)

module.exports = router;